package cn.org.mrliu.ssm.common.service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import cn.org.mrliu.ssm.common.model.BaseModel;
import cn.org.mrliu.ssm.common.web.vo.QueryParam;
import cn.org.mrliu.ssm.util.OrderBy;
import cn.org.mrliu.ssm.util.Pagination;
import cn.org.mrliu.ssm.util.cache.Cache;
import org.springframework.cache.annotation.Cacheable;

/**
 * BaseService接口
 * @author MrLiu
 *
 * @param <Model>
 */
public interface BaseService<Model extends BaseModel> {
	/**
	 * 保存实体
	 * @param model
	 * @throws Exception
	 */
	Integer saveModel(Model model) throws Exception;
	/**
	 * 保存实体不为空的属性
	 * @param model
	 * @throws Exception
	 */
	Integer saveSelectiveModel(Model model) throws Exception;
	/**
	 * 修改实体
	 * @param model
	 * @throws Exception
	 */
	void updateModel(Model model) throws Exception;
	/**
	 * 修改实体不为null的属性
	 * @param model
	 * @throws Exception
	 */
	void updateSelectiveModel(Model model) throws Exception;
	/**
	 * 保存或修改实体,判断ID是否有值,有:修改/无:保存
	 * @param model
	 * @throws Exception
	 */
	Integer saveOrUpdateModel(Model model) throws Exception;
	/**
	 * 删除实体
	 * @param id
	 * @throws Exception
	 */
	void deleteModel(Integer id) throws Exception;
	/**
	 * 根据id获取实体
	 * @param id
	 * @return
	 * @throws Exception
	 */
	Model getModel(Integer id) throws Exception;
	/**
	 * 获取实体的所有的id
	 * @return
	 * @throws Exception
	 */
	List<Integer> getModelIds() throws Exception;
	/**
	 * 根据条件获取实体的id
	 * @param param
	 * @return
	 * @throws Exception
	 */
	List<Integer> getModelIds(Object param) throws Exception;
	/**
	 * 获取实体的所有列表
	 * @return
	 * @throws Exception
	 */
	List<?> getModelList() throws Exception;
	/**
	 * 根据条件获取实体列表
	 * @param param
	 * @return
	 * @throws Exception
	 */
	List<?> getModelList(Object param) throws Exception;
	/**
	 * 获取实体的所有行数
	 * @return
	 * @throws Exception
	 */
	Integer getModelCount() throws Exception;
	/**
	 * 根据条件获取实体的所有行数
	 * @param param
	 * @return
	 * @throws Exception
	 */
	Integer getModelCount(Object param) throws Exception;
	/**
	 * 判断name是否存在
	 * @param name
	 * @return
	 * @throws Exception
	 */
	boolean isExist(String name) throws Exception;
	/**
	 * 判断指定的字段的值是否存在
	 * @param
	 * @return
	 * @throws Exception
	 */
	boolean isExist(Model model) throws Exception;
	/**
	 * 根据页码、页大小获取分页列表
	 * @param pageIndex
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	Pagination getPagination(Integer pageIndex,Integer pageSize) throws Exception;
	/**
	 * 根据页码、页大小、条件获取分页列表
	 * @param pageIndex
	 * @param pageSize
	 * @param param
	 * @return
	 * @throws Exception
	 */
	Pagination getPagination(Integer pageIndex,Integer pageSize,Object param) throws Exception;
	/**
	 * 根据页码、页大小、条件获取分页列表并按指定字段排序
	 * @param pageIndex
	 * @param pageSize
	 * @param param
	 * @param orderBy
	 * @return
	 * @throws Exception
	 */
	Pagination getPagination(Integer pageIndex,Integer pageSize,Object param,String orderBy) throws Exception;
	/**
	 * 根据页码、页大小、条件获取分页列表并按指定字段排序,并指定排序顺序
	 * @param pageIndex
	 * @param pageSize
	 * @param param
	 * @param orderColumn
	 * @param orderBy
	 * @return
	 * @throws Exception
	 */
	Pagination getPagination(Integer pageIndex,Integer pageSize,Object param,String orderColumn,OrderBy orderBy) throws Exception;
	/**
	 * 根据QueryParam获取分页列表
	 * @param queryParam
	 * @return
	 * @throws Exception
	 */
	Pagination getPagination(QueryParam queryParam) throws Exception;
	/**
	 * 根据QueryParam和Map类型的参数获取分页列表
	 * @param queryParam
	 * @param param
	 * @return
	 * @throws Exception
	 */
	@Cacheable(value = "defaultCache")
	Pagination getPagination(QueryParam queryParam,Map<String, Object> param) throws Exception;
	/**
	 * 批量保存实体
	 * @param
	 * @throws Exception
	 */
	void batchSaveModel(Collection<Model> collection) throws Exception;
	/**
	 * 批量保存实体
	 * @param array
	 * @throws Exception
	 */
	void batchSaveModel(Model[] array) throws Exception;
	/**
	 * 批量修改实体
	 * @param model
	 * @param ids
	 * @throws Exception
	 */
	void batchUpdateModel(Model model,Collection<?> ids) throws Exception;
	/**
	 * 批量修改实体
	 * @param model
	 * @param ids
	 * @throws Exception
	 */
	void batchUpdateModel(Model model,Object[] ids) throws Exception;
	/**
	 * 批量删除实体
	 * @param ids
	 * @throws Exception
	 */
	void batchDeleteModel(Collection<?> ids) throws Exception;
	/**
	 * 批量删除实体
	 * @param ids
	 * @throws Exception
	 */
	void batchDeleteModel(Object[] ids) throws Exception;
}
